﻿using System;
using System.Reflection;

/**
 * This was found here: http://stackoverflow.com/questions/2490244/default-value-of-a-type-at-runtime
 */

namespace DeepCompare
{
    /// <summary>
    ///     Generator for default value for an object.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class DefaultGenerator<T>
    {
        public static T GetDefault()
        {
            return default(T);
        }
    }

    /// <summary>
    ///     Generator for default value for an object.
    /// </summary>
    public class DefaultGenerator
    {
        public static object GetDefaultValue(Type parameter)
        {
            var defaultGeneratorType =
                typeof(DefaultGenerator<>).MakeGenericType(parameter);

            return defaultGeneratorType.InvokeMember(
                "GetDefault",
                BindingFlags.Static |
                    BindingFlags.Public |
                    BindingFlags.InvokeMethod,
                null,
                null,
                new object[0]);
        }
    }
}